package cn.edu.gzhu.workOrderManagement.intercepter;

import cn.edu.gzhu.workOrderManagement.constants.MessageConstant;
import cn.edu.gzhu.workOrderManagement.enumeration.UserAuthorityEnum;
import cn.edu.gzhu.workOrderManagement.mapper.WorkOrderMapper;
import cn.edu.gzhu.workOrderManagement.pojo.dto.workOrder.WorkOrderRepeatDto;
import cn.edu.gzhu.workOrderManagement.pojo.entity.WorkOrder;
import cn.edu.gzhu.workOrderManagement.util.ResponseUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.stream.Collectors;

@Component
@Slf4j
//总部商务可以重诉工单

public class WorkOrderRepeatInterceptor implements HandlerInterceptor {
    @Autowired
    WorkOrderMapper workOrderMapper;
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        Claims claims = (Claims)request.getAttribute("claims");
        UserAuthorityEnum authority = UserAuthorityEnum.value2Object( claims.get("authority").toString());
        String username = claims.get("username").toString();
        if(!authority.equals(UserAuthorityEnum.HEAD_BUSINESS)){
            ResponseUtil.failResponse(response, MessageConstant.PERMISSION_DENIED);
            return false;
        }
       return true;
    }



}
